using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace WebFramework.Utils
{
    public class Params
    {
        HttpContext _context;
        public Params(HttpContext context)
        {
            _context = context;
        }

        public ReturnValue<T> GetParam<T>(string paramName)
        {
            string val = _context.Request.QueryString[paramName];
            if (String.IsNullOrEmpty(val))
                return ReturnValue<T>.SetFalse("Parameter doesn't exist");
            try
            {
                T convertedValue = (T)Convert.ChangeType(val, typeof(T));
                return ReturnValue<T>.SetTrue(convertedValue);
            }
            catch (Exception ex)
            {
                return ReturnValue<T>.SetFalse(ex);
            }
        }
    }
}
